package com.sairui.xiaoruilibdemo;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

/**
 * Created by sunqiyong on 2018/6/30.
 */

public class DemoFragment extends Fragment {
    private View mRootView;
    private TextView textView;

    public static DemoFragment getInstance(String s){
        DemoFragment fragment = new DemoFragment();
        Bundle bundle = new Bundle();
        bundle.putString("key",s);
        fragment.setArguments(bundle);
        return fragment;
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        if (mRootView == null) {
            mRootView = inflater.inflate(R.layout.fragment_demo, null);
            initViews();
        }
        ViewGroup parent = (ViewGroup) mRootView.getParent();
        if (parent != null) {
            parent.removeView(mRootView);
        }
        return mRootView;
    }

    private void initViews() {
        textView = mRootView.findViewById(R.id.text);
        TextView tt = mRootView.findViewById(R.id.title);
        textView.setText(getArguments().getString("key"));
        tt.setText(getArguments().getString("key"));
    }
}
